/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package CONTROL;

/**
 *
 * @author Jonathan
 */
import java.sql.*;
public class ServicioBD {
public static final int ORACLEBD=1;
public static final int ACCESSBD=2;
public static  Connection con;
public static  Statement stat ;
public static  ResultSet rs;
public static String connString;
public static String query;
public static Driver driver;

public static void conectar(int bd){
    if(bd==ORACLEBD){
       try {
       Class.forName("oracle.jdbc.OracleDriver");
    connString = "jdbc:oracle:thin:@localhost:1521:xe";
         DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
         con = DriverManager.getConnection(connString, "system", "system");
	 stat = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);    
         System.out.println("coneccion exitosa");      
     } catch (Exception e) {
     System.out.println("coneccion fallo CON ORACLE ");
    e.printStackTrace();
    } finally {

    } 
   }
   /**else
        
     if(bd==ServicioBD.ACCESSBD){

       try{

          driver = (Driver)Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
          con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D:/BankDB/BankDB.accdb");
    
         stat = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
        System.out.println("SE CONECTO CON EXITO A ACCESSS");

     }catch(Exception e){
      System.out.println("ERROR LA CONECTARSE A LA BASE DE DATOS ACCESS");
     }
     }**/       
}
public static void ejecuteQuery(){
    try{
         rs=stat.executeQuery(query);
    }catch(Exception e){
        System.out.println("Hubo un error al ejecutr un UPDATE\n"+query+"\n"+e);
    }
}

public static void ejecuteQuery(String q){
    query=q;
    ejecuteQuery();
}

 
public static boolean ejecuteUpdate(){
    boolean r=true;
    try{
        stat.executeUpdate(query);
        r= true;
    }catch(Exception e){
        System.out.println("Hubo un error al ejecutar un UPDATE\n"+query+"\n"+e);
        r= false;
    }
    return r;
}
public static boolean  ejecuteUpdate(String q){
    boolean r = true;
    query =q;
    r=ejecuteUpdate();
    return r;
}

public static boolean siguiente(){
    boolean r=true;
    try{
        if(ServicioBD.rs.next())
            r=true;
        else
            r=false;
        
    }catch(Exception e){
        System.out.println("Hubo un error al ejecutar un UPDATE\n"+"\n"+e);
    }
    return r;
}
public static boolean anterior(){
    boolean r=true;
    try{
        if(ServicioBD.rs.previous())
            r=true;
        else
            r=false;
        
    }catch(Exception e){
        System.out.println("Hubo un error al ejecutar un UPDATE\n"+"\n"+e);
    }
    return r;
}
public static boolean primero(){
    boolean r=true;
    try{
        if(ServicioBD.rs.first())
            r=true;
        else
            r=false;
        
    }catch(Exception e){
        System.out.println("Hubo un error al ejecutar un UPDATE\n"+"\n"+e);
    }
    return r;
}
public static boolean ultimo(){
    boolean r=true;
    try{
        if(ServicioBD.rs.last())
            r=true;
        else
            r=false;
        
    }catch(Exception e){
        System.out.println("Hubo un error al ejecutar un UPDATE\n"+"\n"+e);
    }
    return r;
}
}
